package sk.xorty.flow.aggregators;

import org.springframework.integration.annotation.Aggregator;
import org.springframework.stereotype.Component;
import sk.xorty.domain.Account;
import sk.xorty.domain.MixedContent;
import sk.xorty.domain.Trade;

import java.util.List;

@Component
public class MixedContentAggregator {

    @Aggregator
    public MixedContent aggregate(List<Object> contents) {
        MixedContent mixedContent = new MixedContent();

        for (Object content : contents) {
            if (content instanceof Trade) {
                mixedContent.setTrade((Trade) content);
            } else if (content instanceof Account) {
                mixedContent.setAccount((Account) content);
            } else {
                throw new IllegalArgumentException(
                        "aggregator found unknown type: " + content);
            }
        }

        return mixedContent;
    }
}
